﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>VIEW FILE</title>
    <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <script type="text/javascript" th:src="@{/layer2.4/layer.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row" style="margin-top: 2%">
        <div class="col-md-8">
            <label th:text="|文件路径 : ${dirId}|"></label>
        </div>
        <div class="col-md-4">
            <button class="btn btn-primary" onclick="window.history.go(0)">刷新</button>
            &nbsp;&nbsp;
            <button class="btn btn-success" onclick="saveContent(1);">保存</button>
            &nbsp;&nbsp;
            <button class="btn btn-info" onclick="saveContent(2);">保存并关闭</button>
            &nbsp;&nbsp;
            <button class="btn btn-danger" onclick="window.close();">关闭</button>
        </div>
    </div>
    <br>
    <div class="row">
        <div class="col-md-12">
            <textarea class="form-control" onfocus="autoSize(this)"  th:text="${content}" id="content"></textarea>
        </div>
    </div>
    <br/>
    <div class="row" style="margin-bottom: 10%">
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
            <button class="btn btn-success" onclick="saveContent(1);">保存</button>
            &nbsp;&nbsp;
            <button class="btn btn-info" onclick="saveContent(2);">保存并关闭</button>
            &nbsp;&nbsp;
            <button class="btn btn-danger" onclick="window.close();">关闭</button>
        </div>
        <div class="col-md-4">
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="javascript">
    var ctx = [[@{/}]];
        ctx = ctx.substr(0, ctx.length - 1);

    var dirId;
    $(function(){
        $("#content").focus();

        dirId = [[${dirId}]];
    });
    
    function saveContent(flag) {
        var content = $("#content").val();

        // content = encodeURI(encodeURI(content));
        // dirId = encodeURI(encodeURI(dirId));

        var data={content:content,dirId:dirId};

        $.ajax({
            url: ctx + "/file/saveContent",
            data:JSON.stringify(data),
            type: 'post',
            async: false,
            dataType:"json",
            contentType:"application/json",
            success: function (data) {
                if (flag==1){
                    layer.msg("保存成功！",{time:2000});
                }else if (flag == 2) {
                    layer.msg("保存成功！",{time:2000,end:function () {
                        window.close();
                     }});
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.responseText);
            }
        })

    }

    function reLoadPage() {
        window.location = window.location;
    }

        // 自动展开textarea
        function autoSize(obj) {
            var el = obj;
            setTimeout(function() {
                el.style.cssText = 'height:auto; padding:0';
                el.style.cssText = 'height:' + el.scrollHeight + 'px';
            }, 0);
        }
</script>
</body>
</html>